package com.zsj.controller;

import com.zsj.config.DataPool;
import com.zsj.entity.DevOpsMaintAllRequest;
import com.zsj.entity.WebResponse;
import com.zsj.enums.ErrorCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 手动请求URL执行的脚本
 */
@Slf4j
@RestController
@RequestMapping("/devops")
public class DevOpsController {
    /**
     * 一键内存维护或者取消维护
     *
     * @param param 请求参数
     */
    @PostMapping(value = "/maintenanceAllProduct")
    public WebResponse maintenanceAllProduct(@RequestBody DevOpsMaintAllRequest param) {
        log.info("一键维护操作，oper:{}", param);

        if (!DataPool.devRequestPassword.equals(param.getPwd())) {
            return WebResponse.fail(ErrorCodeEnum.AUTH_FAIL);
        }

        if (Objects.isNull(param.getOper())) {
            return WebResponse.fail(ErrorCodeEnum.AUTH_FAIL);
        }

        DataPool.maintenanceAllProduct = param.getOper();

        return WebResponse.success();
    }
}
